//
//  StayBehindBusinessViewController.m
//  Utils
//
//  Created by enghou on 2018/4/27.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "StayBehindBusinessViewController.h"
#import "NSMutableDictionary+SetContent.h"
@interface StayBehindBusinessViewController ()

@end

@implementation StayBehindBusinessViewController
-(instancetype)init{
    self = [super init];
    if (self) {
        self.healthModel = [[PropertyDictItemModel alloc]init];
        self.stayPeopleType = [[PropertyDictItemModel alloc]init];
        self.ruhuModel = [[PropertyDictItemModel alloc]init];
        self.mainHealthModel = [[PropertyDictItemModel alloc]init];
        self.relationModel = [[PropertyDictItemModel alloc]init];
    }
    return self;
}
-(NSDictionary *)param{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setContent:self.healthModel.ids forKey:@"leftBehindPeople.health.id" conentNeeded:NO];
    [param setContent:self.personalIncomeField.text forKey:@"leftBehindPeople.personalAnnualIncome" conentNeeded:NO];
    BOOL result = [param setContent:self.stayPeopleType.ids forKey:@"leftBehindPeople.leftType.id" conentNeeded:YES];
    if (!result) {
        [self alertSomes:@"请选择留守人员类型"];
        return nil;
    }
    result = [param setContent:self.ruhuModel.ids forKey:@"leftBehindPeople.householdIdentity.id" conentNeeded:YES];
    if (!result) {
        [self alertSomes:@"请选择入户一致标志!"];
        return nil;
    }
    result = [param setContent:self.idCardField.text forKey:@"leftBehindPeople.familyMainIdCard" conentNeeded:YES];
    if (!result) {
        [self alertSomes:@"请输入家庭主要成员身份证号码!"];
        return nil;
    }
    result = [param setContent:self.nameField.text forKey:@"leftBehindPeople.familyMainName" conentNeeded:YES];
    if (!result) {
        [self alertSomes:@"请输入家庭主要成员姓名!"];
        return nil;
    }
    [param setContent:self.mainHealthModel.ids forKey:@"leftBehindPeople.familyMainHealth.id" conentNeeded:NO];
    result = [param setContent:self.relationModel.ids forKey:@"leftBehindPeople.leftRelationship.id" conentNeeded:YES];
    if (!result) {
        [self alertSomes:@"请选择与留守人员关系!"];
        return nil;
    }
    if ([self.phoneNumberField.text length] == 0  && [self.stablePhoneField.text length] == 0) {
        [self alertSomes:@"请输入联系方式!"];
        return nil;
    }
    [param setContent:self.phoneNumberField.text forKey:@"leftBehindPeople.familyMainPhone" conentNeeded:NO];
    [param setContent:self.stablePhoneField.text forKey:@"leftBehindPeople.familyTelephone" conentNeeded:NO];
    [param setContent:self.incomeField.text forKey:@"leftBehindPeople.familyAnnualIncome" conentNeeded:NO];
    [param setContent:self.workAddressField.text forKey:@"leftBehindPeople.familyMainAdress" conentNeeded:NO];
    [param setContent:self.difficultField.text forKey:@"leftBehindPeople.difficultiesAndDemands" conentNeeded:NO];
    [param setContent:self.helpSituationField.text forKey:@"leftBehindPeople.helpingSituation" conentNeeded:NO];
    return param;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)chooseHealth{
    if (self.healths) {
        [self alertWithArray:self.healths choosenBock:^(PropertyDictItemModel *model) {
            self.healthModel = model;
            self.healthLabel.text = self.healthModel.displayName;
        }];
    }else{
        [self commonAlertWithContent:@"健康状况" choosenBlock:^(PropertyDictItemModel *model) {
            self.healthModel = model;
            self.healthLabel.text = self.healthModel.displayName;
        } getList:^(NSArray *array) {
            self.healths = array;
        }];
    }
}

-(void)choosePeopleType{
    if (self.peopleTypes) {
        [self alertWithArray:self.peopleTypes choosenBock:^(PropertyDictItemModel *model) {
            self.stayPeopleType = model;
            self.stayPeopleTypeField.text = self.stayPeopleType.displayName;
        }];
    }else{
        [self commonAlertWithContent:@"留守人员类型" choosenBlock:^(PropertyDictItemModel *model) {
            self.stayPeopleType = model;
            self.stayPeopleTypeField.text = self.stayPeopleType.displayName;
        } getList:^(NSArray *array) {
            self.peopleTypes = array;
        }];
    }
}

-(void)chooseRuhu{
    if (self.ruhus) {
        [self alertWithArray:self.ruhus choosenBock:^(PropertyDictItemModel *model) {
            self.ruhuModel = model;
            self.ruhuField.text = self.ruhuModel.displayName;
        }];
    }else{
        [self commonAlertWithContent:@"人户状态" choosenBlock:^(PropertyDictItemModel *model) {
            self.ruhuModel = model;
            self.ruhuField.text = self.ruhuModel.displayName;
        } getList:^(NSArray *array) {
            self.ruhus = array;
        }];
    }
}

-(void)chooseMainHealth{
    if (self.healths) {
        [self alertWithArray:self.healths choosenBock:^(PropertyDictItemModel *model) {
            self.mainHealthModel = model;
            self.mainHealthField.text = self.mainHealthModel.displayName;
        }];
    }else{
        [self commonAlertWithContent:@"健康状况" choosenBlock:^(PropertyDictItemModel *model) {
            self.mainHealthModel = model;
            self.mainHealthField.text = self.mainHealthModel.displayName;
        } getList:^(NSArray *array) {
            self.healths = array;
        }];
    }
}

-(void)chooseRelation{
    if (self.relations) {
        [self alertWithArray:self.relations choosenBock:^(PropertyDictItemModel *model) {
            self.relationModel = model;
            self.relationField.text = self.relationModel.displayName;
        }];
    }else{
        [self commonAlertWithContent:@"健康状况" choosenBlock:^(PropertyDictItemModel *model) {
            self.relationModel = model;
            self.relationField.text = self.relationModel.displayName;
        } getList:^(NSArray *array) {
            self.relations = array;
        }];
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        [self chooseHealth];
    }else if (indexPath.row == 2){
        [self choosePeopleType];
    }else if (indexPath.row == 3){
        [self chooseRuhu];
    }else if (indexPath.row == 6){
        [self chooseMainHealth];
    }else if (indexPath.row == 7){
        [self chooseRelation];
    }
}

@end
